import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
    // dispatch-->actions-->mutations-->state
    state: {
        token: '',
        userId:'',
        department:'',
        permission:'',
    },
    mutations: {
        set_token(state, token) {
            state.token = token
            sessionStorage.token = token
        },
        del_token(state) {
            state.token = ''
            sessionStorage.removeItem('token')
        },
        set_info(state,userId){
          state.userId=userId;
          if(userId==16)state.permission='超管';
          else state.permission='管理员';
          window.localStorage.setItem("list",JSON.stringify(state.userId))
        },
        set_department(state,department){
          state.department=department;
          window.localStorage.setItem("list",JSON.stringify(state.department))
        }
    }
})
